package com.dex4d.ui.main.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

import com.dex4d.R;
import com.dex4d.core.AppToolBarBaseActivity;
import com.dex4d.ui.main.model.TradeResult;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;

public class TradeResultActivity extends AppToolBarBaseActivity {

    public static void start(Activity activity, TradeResult tradeResult) {
        Intent intent = new Intent(activity, TradeResultActivity.class);
        intent.putExtra("TradeResult", tradeResult);
        activity.startActivity(intent);
    }

    @BindView(R.id.trade_flag)
    TextView trade_flag;

    @BindView(R.id.trade_amount)
    TextView trade_amount;

    @BindView(R.id.txt_trade_gas)
    TextView trade_gas;

    @BindView(R.id.txt_trade_hash)
    TextView trade_hash;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_trade_result;
    }

    @Override
    protected void initVariables() {
        TradeResult tradeResult = getIntent().getParcelableExtra("TradeResult");
        String flagStr = String.format(getResources().getString(R.string.trade_result_flag), tradeResult.getFlag(this));
        trade_flag.setText(flagStr);
        trade_amount.setText(tradeResult.getAmount());

        String gasStr = String.format(getResources().getString(R.string.trade_result_gas), tradeResult.getGas());
        trade_gas.setText(gasStr);
        trade_hash.setText(tradeResult.getHash());
    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void initToolbar() {
        hideBackView();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_trade_ok, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.manger_trade_done) {
            //TODO 待处理
            finish();
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }


}
